package com.example.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.manager.entity.Teacher;
import com.example.manager.service.TeacherService;

import java.util.List;

@RestController
public class TeacherController {
	
	@Autowired
	private TeacherService service;
	
	@GetMapping("teachers")
	public List<Teacher> getAllTeachers(){
		return service.getAllTeacher();
	}
	
	@GetMapping("teachers/{tid}")
	public Teacher getTeacherByTid(@PathVariable String tid) {
		return service.getTeacherByTid(tid);
	}
	
	@PutMapping("teachers/{tid}")
	public String editTeacher(@PathVariable String tid, Teacher tc) {
		tc.setTid(tid);
		return service.editTeacher(tc);
	}
	
	@PostMapping("teachers")
	public String saveTeacher(Teacher tc) {
		return service.addTeacher(tc);
	}
	
	@DeleteMapping("teachers/{tid}")
	public String delTeacher(@PathVariable String tid) {
		return service.deleteTeacher(tid);
	}
	
}
